package com.yuw.tools;

import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class TestDriver {

	public static void main(String[] args) {
		test02();
	}

	/**
	 * 常用的方法
	 */
	private static void test02() {
		Date d0 = new Date();
		System.out.println("date:" + d0);

		Date d1 = Calendar.getInstance().getTime();
		System.out.println("d1:" + d1);
		
		// get方法获取各种形式的日期
		Calendar c0 = Calendar.getInstance();
		System.out.println("DAY_OF_MONTH:"+c0.get(Calendar.DAY_OF_MONTH));
		System.out.println("DAY_OF_MONTH:"+c0.get(Calendar.DAY_OF_WEEK));
		System.out.println("DAY_OF_YEAR:"+c0.get(Calendar.DAY_OF_YEAR));
	}

	/**
	 * 常用的方法
	 */
	private static void test01() {
		double d0 = -3.14566;
		System.out.println("floor:" + Math.floor(d0));
		System.out.println("ceil:" + Math.ceil(d0));
		System.out.println("round:" + Math.round(d0));
		// 保留两位小数
		System.out.println("round:" + (Math.round(d0 * 100) / 100.0));

		// 返回 [0,1)的随机小数
		// 随机数为1-10；

		System.out.println("随机数1-10：");
		for (int i = 0; i < 20; i++) {
			int val = (int) (Math.random() * 10 + 1);
			System.out.print("    " + val);
		}

		System.out.println("\n随机数0-10：");
		for (int i = 0; i < 20; i++) {
			int val = (int) (Math.random() * 11);
			System.out.print("    " + val);
		}

		System.out.println("\n随机数0-10：");
		Random r0 = new Random();
		for (int i = 0; i < 20; i++) {
			int val = r0.nextInt(11);
			System.out.print("    " + val);
		}
	}
}
